#include <iostream>
#include <algorithm>

using namespace std;

constexpr int maxn = 200000, mod = 1000000007;
int head[maxn + 5], vert[maxn + 5], nxt[maxn + 5], tot;
int f[maxn + 5], sz[maxn + 5], val[maxn + 5], dep[maxn + 5], tg[maxn + 5];
int son[maxn + 5], *dp[maxn + 5], *tag[maxn + 5], c[maxn + 5], s[maxn + 5];
int n, cur;

inline void add(int x, int y)       // 加边 
{
	vert[++tot] = y;
	nxt[tot] = head[x];
	head[x] = tot;
}

inline int qp(int x, int y)        // 快速幂 
{
	int ans = 1;
	for (; y; y >>= 1)
	{
		if (y & 1)
			ans = 1ll * ans * x % mod;
		x = 1ll * x * x % mod;
	}
	return ans;
}

void dfs1(int x)         //  预处理子树大小和重儿子 
{
	sz[x] = 1;
	for (int i = head[x]; i; i = nxt[i])
	{
		int y = vert[i];
		dfs1(y); sz[x] += sz[y];
		if (dep[y] + 1 > dep[x])
		{
			dep[x] = dep[y] + 1;
			son[x] = y;
		}
	}
}

void dfs2(int x)           // 分配dp和tag数组 
{
	dp[x] = f + ++cur; tag[x] = tg + cur;
	if (son[x])
		dfs2(son[x]);
	for (int i = head[x]; i; i = nxt[i])
		if (vert[i] != son[x])
			dfs2(vert[i]);
}

void dfs3(int x)         // 树形dp 
{
	if (1 == sz[x])
	{
		dp[x][0] = 1;
		return;
	}
	
	for (int i = head[x]; i; i = nxt[i])
		dfs3(vert[i]);
	
	int cnt =  0;
	for (int i = head[x]; i; i = nxt[i])
		if (vert[i] != son[x])
			c[++cnt] = vert[i];
	sort(c + 1, c + cnt + 1, [](int x, int y) { return dep[x] > dep[y]; });
	
	if (0 == cnt)
	{
		dp[x][0] = val[sz[x] - 1];
		tag[x][1] = 2ll * tag[x][1] % mod;
		return;
	}
	
	for (int i = 1; i <= cnt; i++)
		for (int d = 0; d <= dep[c[i]]; d++)
			if (tag[c[i]][d] > 1)
			{
				dp[c[i]][d] = 1ll * dp[c[i]][d] * tag[c[i]][d] % mod;
				if (d < dep[c[i]])
					tag[c[i]][d + 1] = 1ll * tag[c[i]][d + 1] * tag[c[i]][d] % mod;
				tag[c[i]][d] = 1;
			}
	
	s[cnt + 1] = 1;
	for (int i = cnt; i >= 1; i--)
		s[i] = 1ll * s[i + 1] * val[sz[c[i]]] % mod;
	
	dp[x][0] = val[sz[x] - 1];
	for (int d = 1; d <= dep[c[1]] + 1; d++)
	{
		if (tag[x][d] > 1)
		{
			dp[x][d] = 1ll * dp[x][d] * tag[x][d] % mod;
			if (d < dep[x])
				tag[x][d + 1] = 1ll * tag[x][d + 1] * tag[x][d] % mod;
			tag[x][d] = 1;
		}
		
		int cur = (val[sz[son[x]]] - dp[x][d]) % mod, i;
		for (i = 1; i <= cnt && d <= dep[c[i]] + 1; i++)
			cur = 1ll * (val[sz[c[i]]] - dp[c[i]][d - 1]) % mod * cur % mod;
		if (i <= cnt)
			cur = 1ll * cur * s[i] % mod;
		dp[x][d] = 1ll * cur * qp((val[sz[son[x]]] - dp[x][d]) % mod, mod - 2) % mod * dp[x][d] % mod;
		for (i = 1; i <= cnt && d <= dep[c[i]] + 1; i++)
			dp[x][d] = (dp[x][d] + 1ll * cur * qp((val[sz[c[i]]] - dp[c[i]][d - 1]) % mod, mod - 2) % mod * dp[c[i]][d - 1] % mod) % mod;
		dp[x][d] = 2ll * dp[x][d] % mod;
	}
	if (dep[c[1]] + 1 < dep[x])
		tag[x][dep[c[1]] + 2] = 2ll * tag[x][dep[c[1]] + 2] % mod * s[1] % mod;
}

int main()
{
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int f; cin >> f;
		add(f, i);
	}
	val[0] = 1;
	for (int i = 1; i <= n + 1; i++)       // 预处理2的幂 
		val[i] = 2ll * val[i - 1] % mod;
	
	dfs1(0); dfs2(0);
	for (int i = 1; i <= n + 1; i++)
		tg[i] = 1;
	dfs3(0);
		
	int ans = 0;
	for (int i = 0; i <= dep[0]; i++)     // 统计答案 
	{
		if (tag[0][i] > 1)
		{
			dp[0][i] = 1ll * dp[0][i] * tag[0][i] % mod;
			if (i < dep[0])
				tag[0][i + 1] = 1ll * tag[0][i + 1] * tag[0][i] % mod;
			tag[0][i] = 1;
		}
		ans = (ans + dp[0][i]) % mod;
	}
	cout << (ans + mod) % mod << endl;
	
	return 0;
}
